﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class View_RepairStatusHistories : _View_RepairStatusHistories
    {
        public static View_RepairStatusHistories GetCurrentJobHists()
        {
            try
            {
                View_RepairStatusHistories jobSts = new View_RepairStatusHistories();
                jobSts.Where.LastStatusID.Value = RepairStatus.Returned;
                jobSts.Where.LastStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.NotEqual;

                MyGeneration.dOOdads.WhereParameter whereStatusID = jobSts.Where.TearOff.LastStatusID;
                whereStatusID.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.Or;
                whereStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.IsNull;

                jobSts.Query.Load();
                return jobSts;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetCurrentJobProblems", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairStatusHistories GetJobStatusHistByNo(string no)
        {
            try
            {
                View_RepairStatusHistories jobSts = new View_RepairStatusHistories();
                jobSts.Where.RepairNo.Value = no;

                jobSts.Query.Load();
                return jobSts;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairStatusHistories.cs", "GetJobStatusHistByNo", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairStatusHistories GetJobStatusHistByRepairModelID(int id)
        {
            try
            {
                View_RepairStatusHistories jobSts = new View_RepairStatusHistories();
                jobSts.Where.RepairModelID.Value = id;

                jobSts.Query.Load();
                return jobSts;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairStatusHistories.cs", "GetJobStatusHistByRepairModelID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairStatusHistories GetJobStatusHistByIMEI(string imei)
        {
            try
            {
                View_RepairStatusHistories jobSts = new View_RepairStatusHistories();
                jobSts.Where.IMEI.Value = imei;

                jobSts.Query.Load();
                return jobSts;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairStatusHistories.cs", "GetJobStatusHistByIMEI", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairStatusHistories GetDoneOrRejectedJobSts()
        {
            try
            {
                View_RepairStatusHistories jobSts = new View_RepairStatusHistories();
                jobSts.Where.LastStatusID.Value = RepairStatus.Done;

                MyGeneration.dOOdads.WhereParameter whereStatusID = jobSts.Where.TearOff.LastStatusID;
                whereStatusID.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.Or;
                whereStatusID.Value = RepairStatus.Rejected;

                jobSts.Query.Load();
                return jobSts;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetDoneOrRejectedJobSts", ex.StackTrace);
                throw ex;
            }
        }
    }
}
